{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. [ 按列选择数据（返回数据格式为Series）](#%E6%8C%89%E5%88%97%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%EF%BC%88%E8%BF%94%E5%9B%9E%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F%E4%B8%BASeries%EF%BC%89)\n",
    "2. [按行选取数据](#%E6%8C%89%E8%A1%8C%E9%80%89%E5%8F%96%E6%95%B0%E6%8D%AE)\n",
    "3. [根据行列选取数据](#%E6%A0%B9%E6%8D%AE%E8%A1%8C%E5%88%97%E9%80%89%E5%8F%96%E6%95%B0%E6%8D%AE)\n",
    "4. [同时使用下标（数字）和名字索引](#%E5%90%8C%E6%97%B6%E4%BD%BF%E7%94%A8%E4%B8%8B%E6%A0%87%EF%BC%88%E6%95%B0%E5%AD%97%EF%BC%89%E5%92%8C%E5%90%8D%E5%AD%97%E7%B4%A2%E5%BC%95)\n",
    "5. [加速标量选择](#%E5%8A%A0%E9%80%9F%E6%A0%87%E9%87%8F%E9%80%89%E6%8B%A9)\n",
    "6. [懒人切片法](#%E6%87%92%E4%BA%BA%E5%88%87%E7%89%87%E6%B3%95)\n",
    "7. [字典序切片](#%E5%AD%97%E5%85%B8%E5%BA%8F%E5%88%87%E7%89%87)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 按列选择数据（返回数据格式为Series）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University                   Normal\n",
       "University of Alabama at Birmingham    Birmingham\n",
       "Amridge University                     Montgomery\n",
       "University of Alabama in Huntsville    Huntsville\n",
       "Alabama State University               Montgomery\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "city = college['CITY']\n",
    "city.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Huntsville'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.iloc[3] # iloc使用数字索引，先行后列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Birmingham Southern College                            Birmingham\n",
       "George C Wallace State Community College-Hanceville    Hanceville\n",
       "Judson College                                             Marion\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.iloc[[10,20,30]] # 选取多行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama State University              Montgomery\n",
       "Enterprise State Community College    Enterprise\n",
       "Heritage Christian University           Florence\n",
       "Marion Military Institute                 Marion\n",
       "Reid State Technical College           Evergreen\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.iloc[4:50:10] # 类似与Java这么写for (int i = 4; i < 50; i += 10) { ... }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Birmingham'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.loc['University of Alabama at Birmingham'] # loc使用名字做索引，先行后列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Northwest HVAC/R Training Center',\n",
       " 'California State University-Dominguez Hills',\n",
       " 'Lower Columbia College',\n",
       " 'Southwest Acupuncture College-Boulder']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(1)\n",
    "labels = list(np.random.choice(city.index, 4)) # 从city.index随机挑4条数据\n",
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Northwest HVAC/R Training Center                Spokane\n",
       "California State University-Dominguez Hills      Carson\n",
       "Lower Columbia College                         Longview\n",
       "Southwest Acupuncture College-Boulder           Boulder\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.loc[labels]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama State University              Montgomery\n",
       "Enterprise State Community College    Enterprise\n",
       "Heritage Christian University           Florence\n",
       "Marion Military Institute                 Marion\n",
       "Reid State Technical College           Evergreen\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 系统会根据Alabama ...和Reid S...的索引为开始结束位置自动计算\n",
    "# 名字索引与下标索引不同，是闭区间，只要能找到就会被选取。\n",
    "# for (int i = start; i <= end; i += 10) { ... }\n",
    "city.loc['Alabama State University':'Reid State Technical College':10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama State University              Montgomery\n",
       "Enterprise State Community College    Enterprise\n",
       "Heritage Christian University           Florence\n",
       "Marion Military Institute                 Marion\n",
       "Reid State Technical College           Evergreen\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city['Alabama State University':'Reid State Technical College':10] # 因为是Series，所以直接上索引就行，不用像DataFrame要考虑默认顺序。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "University of Alabama in Huntsville    Huntsville\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.iloc[[3]] # 访问第3行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Series([], Name: CITY, dtype: object)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city.loc['Reid State Technical College':'Alabama State University':10] # 没数据，看下索引位置就知道为什么了。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Reid State Technical College           Evergreen\n",
       "Marion Military Institute                 Marion\n",
       "Heritage Christian University           Florence\n",
       "Enterprise State Community College    Enterprise\n",
       "Alabama State University              Montgomery\n",
       "Name: CITY, dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 如果start比end大，就是for (int i = start; i > end; i -= 10) { ... }\n",
    "city.loc['Reid State Technical College':'Alabama State University':-10]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 按行选取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>424.0</td>\n",
       "      <td>420.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4206.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "      <td>0.0656</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7356</td>\n",
       "      <td>0.8284</td>\n",
       "      <td>0.1049</td>\n",
       "      <td>30300</td>\n",
       "      <td>33888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>570.0</td>\n",
       "      <td>565.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11383.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "      <td>0.2607</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3460</td>\n",
       "      <td>0.5214</td>\n",
       "      <td>0.2422</td>\n",
       "      <td>39700</td>\n",
       "      <td>21941.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>291.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "      <td>0.4536</td>\n",
       "      <td>1</td>\n",
       "      <td>0.6801</td>\n",
       "      <td>0.7795</td>\n",
       "      <td>0.8540</td>\n",
       "      <td>40100</td>\n",
       "      <td>23370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>425.0</td>\n",
       "      <td>430.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4811.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "      <td>0.0892</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7347</td>\n",
       "      <td>0.7554</td>\n",
       "      <td>0.1270</td>\n",
       "      <td>26600</td>\n",
       "      <td>33118.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 Normal     AL   1.0      0.0   \n",
       "University of Alabama at Birmingham  Birmingham     AL   0.0      0.0   \n",
       "Amridge University                   Montgomery     AL   0.0      0.0   \n",
       "University of Alabama in Huntsville  Huntsville     AL   0.0      0.0   \n",
       "Alabama State University             Montgomery     AL   1.0      0.0   \n",
       "\n",
       "                                     WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                         \n",
       "Alabama A & M University                   0.0         0     424.0     420.0   \n",
       "University of Alabama at Birmingham        0.0         0     570.0     565.0   \n",
       "Amridge University                         0.0         1       NaN       NaN   \n",
       "University of Alabama in Huntsville        0.0         0     595.0     590.0   \n",
       "Alabama State University                   0.0         0     425.0     430.0   \n",
       "\n",
       "                                     DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                      ...              \n",
       "Alabama A & M University                      0.0   4206.0  ...     0.0000   \n",
       "University of Alabama at Birmingham           0.0  11383.0  ...     0.0368   \n",
       "Amridge University                            1.0    291.0  ...     0.0000   \n",
       "University of Alabama in Huntsville           0.0   5451.0  ...     0.0172   \n",
       "Alabama State University                      0.0   4811.0  ...     0.0098   \n",
       "\n",
       "                                     UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                         \n",
       "Alabama A & M University               0.0059     0.0138    0.0656         1   \n",
       "University of Alabama at Birmingham    0.0179     0.0100    0.2607         1   \n",
       "Amridge University                     0.0000     0.2715    0.4536         1   \n",
       "University of Alabama in Huntsville    0.0332     0.0350    0.2146         1   \n",
       "Alabama State University               0.0243     0.0137    0.0892         1   \n",
       "\n",
       "                                     PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                            \n",
       "Alabama A & M University              0.7356    0.8284   0.1049   \n",
       "University of Alabama at Birmingham   0.3460    0.5214   0.2422   \n",
       "Amridge University                    0.6801    0.7795   0.8540   \n",
       "University of Alabama in Huntsville   0.3072    0.4596   0.2640   \n",
       "Alabama State University              0.7347    0.7554   0.1270   \n",
       "\n",
       "                                     MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                    \n",
       "Alabama A & M University                       30300               33888  \n",
       "University of Alabama at Birmingham            39700             21941.5  \n",
       "Amridge University                             40100               23370  \n",
       "University of Alabama in Huntsville            45500               24097  \n",
       "Alabama State University                       26600             33118.5  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.options.display.max_rows = 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CITY                  Anchorage\n",
       "STABBR                       AK\n",
       "HBCU                          0\n",
       "                        ...    \n",
       "UG25ABV                  0.4386\n",
       "MD_EARN_WNE_P10           42500\n",
       "GRAD_DEBT_MDN_SUPP      19449.5\n",
       "Name: University of Alaska Anchorage, Length: 26, dtype: object"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[60] # 显示第60行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CITY                  Anchorage\n",
       "STABBR                       AK\n",
       "HBCU                          0\n",
       "                        ...    \n",
       "UG25ABV                  0.4386\n",
       "MD_EARN_WNE_P10           42500\n",
       "GRAD_DEBT_MDN_SUPP      19449.5\n",
       "Name: University of Alaska Anchorage, Length: 26, dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc['University of Alaska Anchorage'] # 根据索引的名字定位行，iloc直接找数字下标，loc找索引名字。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>University of Alaska Anchorage</th>\n",
       "      <td>Anchorage</td>\n",
       "      <td>AK</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12865.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0980</td>\n",
       "      <td>0.0181</td>\n",
       "      <td>0.0457</td>\n",
       "      <td>0.4539</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2385</td>\n",
       "      <td>0.2647</td>\n",
       "      <td>0.4386</td>\n",
       "      <td>42500</td>\n",
       "      <td>19449.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                   \n",
       "University of Alaska Anchorage         Anchorage     AK   0.0      0.0   \n",
       "International Academy of Hair Design       Tempe     AZ   0.0      0.0   \n",
       "University of Alabama in Huntsville   Huntsville     AL   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage              0.0         0       NaN       NaN   \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "University of Alabama in Huntsville         0.0         0     595.0     590.0   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "University of Alaska Anchorage                 0.0  12865.0  ...     0.0980   \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "University of Alabama in Huntsville            0.0   5451.0  ...     0.0172   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage          0.0181     0.0457    0.4539         1   \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "University of Alabama in Huntsville     0.0332     0.0350    0.2146         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "University of Alaska Anchorage         0.2385    0.2647   0.4386   \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "University of Alabama in Huntsville    0.3072    0.4596   0.2640   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "University of Alaska Anchorage                  42500             19449.5  \n",
       "International Academy of Hair Design            22200               10556  \n",
       "University of Alabama in Huntsville             45500               24097  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[[60, 99, 3]] # 选取第60，99，3行。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>University of Alaska Anchorage</th>\n",
       "      <td>Anchorage</td>\n",
       "      <td>AK</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12865.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0980</td>\n",
       "      <td>0.0181</td>\n",
       "      <td>0.0457</td>\n",
       "      <td>0.4539</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2385</td>\n",
       "      <td>0.2647</td>\n",
       "      <td>0.4386</td>\n",
       "      <td>42500</td>\n",
       "      <td>19449.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                   \n",
       "University of Alaska Anchorage         Anchorage     AK   0.0      0.0   \n",
       "International Academy of Hair Design       Tempe     AZ   0.0      0.0   \n",
       "University of Alabama in Huntsville   Huntsville     AL   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage              0.0         0       NaN       NaN   \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "University of Alabama in Huntsville         0.0         0     595.0     590.0   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "University of Alaska Anchorage                 0.0  12865.0  ...     0.0980   \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "University of Alabama in Huntsville            0.0   5451.0  ...     0.0172   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "University of Alaska Anchorage          0.0181     0.0457    0.4539         1   \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "University of Alabama in Huntsville     0.0332     0.0350    0.2146         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "University of Alaska Anchorage         0.2385    0.2647   0.4386   \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "University of Alabama in Huntsville    0.3072    0.4596   0.2640   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "University of Alaska Anchorage                  42500             19449.5  \n",
       "International Academy of Hair Design            22200               10556  \n",
       "University of Alabama in Huntsville             45500               24097  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels = ['University of Alaska Anchorage',\n",
    "          'International Academy of Hair Design',\n",
    "          'University of Alabama in Huntsville']\n",
    "college.loc[labels] # 选取指定索引名字的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>Phoenix</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5211.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0127</td>\n",
       "      <td>0.0161</td>\n",
       "      <td>0.0702</td>\n",
       "      <td>0.7465</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3270</td>\n",
       "      <td>0.2189</td>\n",
       "      <td>0.5832</td>\n",
       "      <td>29800</td>\n",
       "      <td>7283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mesa Community College</th>\n",
       "      <td>Mesa</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19055.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0205</td>\n",
       "      <td>0.0257</td>\n",
       "      <td>0.0682</td>\n",
       "      <td>0.6457</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3423</td>\n",
       "      <td>0.2207</td>\n",
       "      <td>0.4010</td>\n",
       "      <td>35200</td>\n",
       "      <td>8000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                \n",
       "International Academy of Hair Design    Tempe     AZ   0.0      0.0   \n",
       "GateWay Community College             Phoenix     AZ   0.0      0.0   \n",
       "Mesa Community College                   Mesa     AZ   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "GateWay Community College                   0.0         0       NaN       NaN   \n",
       "Mesa Community College                      0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "GateWay Community College                      0.0   5211.0  ...     0.0127   \n",
       "Mesa Community College                         0.0  19055.0  ...     0.0205   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "GateWay Community College               0.0161     0.0702    0.7465         1   \n",
       "Mesa Community College                  0.0257     0.0682    0.6457         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "GateWay Community College              0.3270    0.2189   0.5832   \n",
       "Mesa Community College                 0.3423    0.2207   0.4010   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "International Academy of Hair Design            22200               10556  \n",
       "GateWay Community College                       29800                7283  \n",
       "Mesa Community College                          35200                8000  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[99:102] # 90 <= row < 102"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>International Academy of Hair Design</th>\n",
       "      <td>Tempe</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>188.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0160</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0638</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7185</td>\n",
       "      <td>0.7346</td>\n",
       "      <td>0.3905</td>\n",
       "      <td>22200</td>\n",
       "      <td>10556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>Phoenix</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5211.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0127</td>\n",
       "      <td>0.0161</td>\n",
       "      <td>0.0702</td>\n",
       "      <td>0.7465</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3270</td>\n",
       "      <td>0.2189</td>\n",
       "      <td>0.5832</td>\n",
       "      <td>29800</td>\n",
       "      <td>7283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mesa Community College</th>\n",
       "      <td>Mesa</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19055.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0205</td>\n",
       "      <td>0.0257</td>\n",
       "      <td>0.0682</td>\n",
       "      <td>0.6457</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3423</td>\n",
       "      <td>0.2207</td>\n",
       "      <td>0.4010</td>\n",
       "      <td>35200</td>\n",
       "      <td>8000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                \n",
       "International Academy of Hair Design    Tempe     AZ   0.0      0.0   \n",
       "GateWay Community College             Phoenix     AZ   0.0      0.0   \n",
       "Mesa Community College                   Mesa     AZ   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design        0.0         0       NaN       NaN   \n",
       "GateWay Community College                   0.0         0       NaN       NaN   \n",
       "Mesa Community College                      0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "International Academy of Hair Design           0.0    188.0  ...     0.0160   \n",
       "GateWay Community College                      0.0   5211.0  ...     0.0127   \n",
       "Mesa Community College                         0.0  19055.0  ...     0.0205   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "International Academy of Hair Design    0.0000     0.0638    0.0000         0   \n",
       "GateWay Community College               0.0161     0.0702    0.7465         1   \n",
       "Mesa Community College                  0.0257     0.0682    0.6457         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "International Academy of Hair Design   0.7185    0.7346   0.3905   \n",
       "GateWay Community College              0.3270    0.2189   0.5832   \n",
       "Mesa Community College                 0.3423    0.2207   0.4010   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "International Academy of Hair Design            22200               10556  \n",
       "GateWay Community College                       29800                7283  \n",
       "Mesa Community College                          35200                8000  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start = 'International Academy of Hair Design'\n",
    "stop = 'Mesa Community College'\n",
    "college.loc[start:stop] # 用名字索引的时候两边都是闭区间，只要能找到就会被选取。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['University of Alaska Anchorage',\n",
       " 'International Academy of Hair Design',\n",
       " 'University of Alabama in Huntsville']"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[[60, 99, 3]].index.tolist() # 获取指定行的索引并转换成数组list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 根据行列选取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR  HBCU  MENONLY\n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 Normal     AL   1.0      0.0\n",
       "University of Alabama at Birmingham  Birmingham     AL   0.0      0.0\n",
       "Amridge University                   Montgomery     AL   0.0      0.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college.iloc[:3, :4] # 前3行，前4列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR  HBCU  MENONLY\n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 Normal     AL   1.0      0.0\n",
       "University of Alabama at Birmingham  Birmingham     AL   0.0      0.0\n",
       "Amridge University                   Montgomery     AL   0.0      0.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc[:'Amridge University', :'MENONLY'] # 'Amridge University'之前的行（包含），'MENONLY'之前的列（包含）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>SATVRMID</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>424.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.0</td>\n",
       "      <td>570.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.0</td>\n",
       "      <td>595.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>425.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     WOMENONLY  SATVRMID\n",
       "INSTNM                                                  \n",
       "Alabama A & M University                   0.0     424.0\n",
       "University of Alabama at Birmingham        0.0     570.0\n",
       "Amridge University                         0.0       NaN\n",
       "University of Alabama in Huntsville        0.0     595.0\n",
       "Alabama State University                   0.0     425.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[:, [4,6]].head() # 所有行，以及第4，6列的前几条数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>SATVRMID</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>424.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.0</td>\n",
       "      <td>570.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    WOMENONLY  SATVRMID\n",
       "INSTNM                                                                 \n",
       "Alabama A & M University                                  0.0     424.0\n",
       "University of Alabama at Birmingham                       0.0     570.0\n",
       "Amridge University                                        0.0       NaN\n",
       "...                                                       ...       ...\n",
       "National Personal Training Institute of Cleveland         NaN       NaN\n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN       NaN\n",
       "Excel Learning Center-San Antonio South                   NaN       NaN\n",
       "\n",
       "[7535 rows x 2 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc[:, ['WOMENONLY', 'SATVRMID']] # 所有行，以及指定的两列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>American Baptist Seminary of the West</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       SATMTMID  UGDS_NHPI\n",
       "INSTNM                                                    \n",
       "GateWay Community College                   NaN     0.0029\n",
       "American Baptist Seminary of the West       NaN        NaN"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[[100, 200], [7, 15]] # 根据下标索引指定行列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>GateWay Community College</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>American Baptist Seminary of the West</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       SATMTMID  UGDS_NHPI\n",
       "INSTNM                                                    \n",
       "GateWay Community College                   NaN     0.0029\n",
       "American Baptist Seminary of the West       NaN        NaN"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rows = ['GateWay Community College', 'American Baptist Seminary of the West']\n",
    "columns = ['SATMTMID', 'UGDS_NHPI']\n",
    "college.loc[rows, columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.401"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[5, -4] # 负数索引就是倒数第X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.401"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc['The University of Alabama', 'PCTFLOAN'] # 类似二维数组的d2[x][y]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Empire Beauty School-Flagstaff     0\n",
       "Charles of Italy Beauty College    0\n",
       "Central Arizona College            0\n",
       "University of Arizona              0\n",
       "Arizona State University-Tempe     0\n",
       "Name: RELAFFIL, dtype: int64"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "for (int row = 90; row > 80; row -= 2) {\n",
    "  college[row][5]\n",
    "}\n",
    "'''\n",
    "college.iloc[90:80:-2, 5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Empire Beauty School-Flagstaff     0\n",
       "Charles of Italy Beauty College    0\n",
       "Central Arizona College            0\n",
       "University of Arizona              0\n",
       "Arizona State University-Tempe     0\n",
       "Name: RELAFFIL, dtype: int64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start = 'Empire Beauty School-Flagstaff'\n",
    "stop = 'Arizona State University-Tempe'\n",
    "college.loc[start:stop:-2, 'RELAFFIL'] # 闭区间，如果最后一条记录包含stop则被选取。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 同时使用下标（数字）和名字索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(10, 19)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col_start = college.columns.get_loc('UGDS_WHITE') # 根据索引名字获取下标位置\n",
    "col_end = college.columns.get_loc('UGDS_UNKN') + 1\n",
    "col_start, col_end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.iloc[:5, col_start:col_end] # 前5行，从'UGDS_WHITE'列开始到'UGDS_UNKN'列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Birmingham Southern College</th>\n",
       "      <td>0.7983</td>\n",
       "      <td>0.1102</td>\n",
       "      <td>0.0195</td>\n",
       "      <td>0.0517</td>\n",
       "      <td>0.0102</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0051</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chattahoochee Valley Community College</th>\n",
       "      <td>0.4661</td>\n",
       "      <td>0.4372</td>\n",
       "      <td>0.0492</td>\n",
       "      <td>0.0127</td>\n",
       "      <td>0.0023</td>\n",
       "      <td>0.0035</td>\n",
       "      <td>0.0151</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Concordia College Alabama</th>\n",
       "      <td>0.0280</td>\n",
       "      <td>0.8758</td>\n",
       "      <td>0.0373</td>\n",
       "      <td>0.0093</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0031</td>\n",
       "      <td>0.0466</td>\n",
       "      <td>0.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>South University-Montgomery</th>\n",
       "      <td>0.3046</td>\n",
       "      <td>0.6054</td>\n",
       "      <td>0.0153</td>\n",
       "      <td>0.0153</td>\n",
       "      <td>0.0153</td>\n",
       "      <td>0.0096</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Enterprise State Community College</th>\n",
       "      <td>0.6408</td>\n",
       "      <td>0.2435</td>\n",
       "      <td>0.0509</td>\n",
       "      <td>0.0202</td>\n",
       "      <td>0.0081</td>\n",
       "      <td>0.0029</td>\n",
       "      <td>0.0254</td>\n",
       "      <td>0.0012</td>\n",
       "      <td>0.0069</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>James H Faulkner State Community College</th>\n",
       "      <td>0.6979</td>\n",
       "      <td>0.2259</td>\n",
       "      <td>0.0320</td>\n",
       "      <td>0.0084</td>\n",
       "      <td>0.0177</td>\n",
       "      <td>0.0014</td>\n",
       "      <td>0.0152</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0009</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                        \n",
       "Birmingham Southern College                   0.7983      0.1102     0.0195   \n",
       "Chattahoochee Valley Community College        0.4661      0.4372     0.0492   \n",
       "Concordia College Alabama                     0.0280      0.8758     0.0373   \n",
       "South University-Montgomery                   0.3046      0.6054     0.0153   \n",
       "Enterprise State Community College            0.6408      0.2435     0.0509   \n",
       "James H Faulkner State Community College      0.6979      0.2259     0.0320   \n",
       "\n",
       "                                          UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                       \n",
       "Birmingham Southern College                   0.0517     0.0102     0.0000   \n",
       "Chattahoochee Valley Community College        0.0127     0.0023     0.0035   \n",
       "Concordia College Alabama                     0.0093     0.0000     0.0000   \n",
       "South University-Montgomery                   0.0153     0.0153     0.0096   \n",
       "Enterprise State Community College            0.0202     0.0081     0.0029   \n",
       "James H Faulkner State Community College      0.0084     0.0177     0.0014   \n",
       "\n",
       "                                          UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                                    \n",
       "Birmingham Southern College                  0.0051    0.0000     0.0051  \n",
       "Chattahoochee Valley Community College       0.0151    0.0000     0.0139  \n",
       "Concordia College Alabama                    0.0031    0.0466     0.0000  \n",
       "South University-Montgomery                  0.0000    0.0019     0.0326  \n",
       "Enterprise State Community College           0.0254    0.0012     0.0069  \n",
       "James H Faulkner State Community College     0.0152    0.0007     0.0009  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_start = college.index[10]\n",
    "row_end = college.index[15]\n",
    "college.loc[row_start:row_end, 'UGDS_WHITE':'UGDS_UNKN'] # 10到15行，共6行数据。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 加速标量选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 所谓标量就是理解选择一个数据，如果一次选择一列或一行就是向量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6609999999999999"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "cn = 'Texas A & M University-College Station'\n",
    "college.loc[cn, 'UGDS_WHITE']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6609999999999999"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.at[cn, 'UGDS_WHITE'] # 功能与loc一样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.07 µs ± 110 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.loc[cn, 'UGDS_WHITE']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.36 µs ± 19.5 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.at[cn, 'UGDS_WHITE'] # at比loc快"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3765, 10)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_num = college.index.get_loc(cn)\n",
    "col_num = college.columns.get_loc('UGDS_WHITE')\n",
    "row_num, col_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.56 µs ± 86.4 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iloc[row_num, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.97 µs ± 88.5 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iat[row_num, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8.26 µs ± 698 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iloc[5, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.99 µs ± 142 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit college.iat[5, col_num]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "state = college['STABBR']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'IL'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state.iat[1000]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'CA'"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "state.at['Stanford University']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 懒人切片法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Birmingham Southern College</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>560.0</td>\n",
       "      <td>560.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1180.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0051</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0051</td>\n",
       "      <td>0.0017</td>\n",
       "      <td>1</td>\n",
       "      <td>0.1920</td>\n",
       "      <td>0.4809</td>\n",
       "      <td>0.0152</td>\n",
       "      <td>44200</td>\n",
       "      <td>27000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Concordia College Alabama</th>\n",
       "      <td>Selma</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>420.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>322.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0031</td>\n",
       "      <td>0.0466</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.1056</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8667</td>\n",
       "      <td>0.9333</td>\n",
       "      <td>0.2367</td>\n",
       "      <td>19900</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Enterprise State Community College</th>\n",
       "      <td>Enterprise</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1729.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0254</td>\n",
       "      <td>0.0012</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.3823</td>\n",
       "      <td>1</td>\n",
       "      <td>0.4895</td>\n",
       "      <td>0.2263</td>\n",
       "      <td>0.3399</td>\n",
       "      <td>24600</td>\n",
       "      <td>8273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Faulkner University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2367.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0173</td>\n",
       "      <td>0.0182</td>\n",
       "      <td>0.0258</td>\n",
       "      <td>0.2302</td>\n",
       "      <td>1</td>\n",
       "      <td>0.5812</td>\n",
       "      <td>0.7253</td>\n",
       "      <td>0.4589</td>\n",
       "      <td>37200</td>\n",
       "      <td>22000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Beginning College of Cosmetology</th>\n",
       "      <td>Albertville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0783</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8224</td>\n",
       "      <td>0.8553</td>\n",
       "      <td>0.3933</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                    \n",
       "Birmingham Southern College            Birmingham     AL   0.0      0.0   \n",
       "Concordia College Alabama                   Selma     AL   1.0      0.0   \n",
       "Enterprise State Community College     Enterprise     AL   0.0      0.0   \n",
       "Faulkner University                    Montgomery     AL   0.0      0.0   \n",
       "New Beginning College of Cosmetology  Albertville     AL   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "Birmingham Southern College                 0.0         1     560.0     560.0   \n",
       "Concordia College Alabama                   0.0         1     420.0     400.0   \n",
       "Enterprise State Community College          0.0         0       NaN       NaN   \n",
       "Faulkner University                         0.0         1       NaN       NaN   \n",
       "New Beginning College of Cosmetology        0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY    UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                      ...              \n",
       "Birmingham Southern College                    0.0  1180.0  ...     0.0051   \n",
       "Concordia College Alabama                      0.0   322.0  ...     0.0031   \n",
       "Enterprise State Community College             0.0  1729.0  ...     0.0254   \n",
       "Faulkner University                            0.0  2367.0  ...     0.0173   \n",
       "New Beginning College of Cosmetology           0.0   115.0  ...     0.0000   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "Birmingham Southern College             0.0000     0.0051    0.0017         1   \n",
       "Concordia College Alabama               0.0466     0.0000    0.1056         1   \n",
       "Enterprise State Community College      0.0012     0.0069    0.3823         1   \n",
       "Faulkner University                     0.0182     0.0258    0.2302         1   \n",
       "New Beginning College of Cosmetology    0.0000     0.0000    0.0783         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "Birmingham Southern College            0.1920    0.4809   0.0152   \n",
       "Concordia College Alabama              0.8667    0.9333   0.2367   \n",
       "Enterprise State Community College     0.4895    0.2263   0.3399   \n",
       "Faulkner University                    0.5812    0.7253   0.4589   \n",
       "New Beginning College of Cosmetology   0.8224    0.8553   0.3933   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "Birmingham Southern College                     44200               27000  \n",
       "Concordia College Alabama                       19900   PrivacySuppressed  \n",
       "Enterprise State Community College              24600                8273  \n",
       "Faulkner University                             37200               22000  \n",
       "New Beginning College of Cosmetology              NaN                5500  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college[10:20:2] # 10, 12, 14, 16, 18行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Spokane Community College'"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.index[4001] # 第4001行的索引名称"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Mesa Community College</th>\n",
       "      <td>Mesa</td>\n",
       "      <td>AZ</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19055.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0205</td>\n",
       "      <td>0.0257</td>\n",
       "      <td>0.0682</td>\n",
       "      <td>0.6457</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3423</td>\n",
       "      <td>0.2207</td>\n",
       "      <td>0.4010</td>\n",
       "      <td>35200</td>\n",
       "      <td>8000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Hair Academy Inc-New Carrollton</th>\n",
       "      <td>New Carrollton</td>\n",
       "      <td>MD</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>504.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.4683</td>\n",
       "      <td>1</td>\n",
       "      <td>0.9756</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.5882</td>\n",
       "      <td>15200</td>\n",
       "      <td>9666</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National College of Natural Medicine</th>\n",
       "      <td>Portland</td>\n",
       "      <td>OR</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                       \n",
       "Mesa Community College                          Mesa     AZ   0.0      0.0   \n",
       "Hair Academy Inc-New Carrollton       New Carrollton     MD   0.0      0.0   \n",
       "National College of Natural Medicine        Portland     OR   0.0      0.0   \n",
       "\n",
       "                                      WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  \\\n",
       "INSTNM                                                                          \n",
       "Mesa Community College                      0.0         0       NaN       NaN   \n",
       "Hair Academy Inc-New Carrollton             0.0         0       NaN       NaN   \n",
       "National College of Natural Medicine        0.0         0       NaN       NaN   \n",
       "\n",
       "                                      DISTANCEONLY     UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                       ...              \n",
       "Mesa Community College                         0.0  19055.0  ...     0.0205   \n",
       "Hair Academy Inc-New Carrollton                0.0    504.0  ...     0.0000   \n",
       "National College of Natural Medicine           0.0      NaN  ...        NaN   \n",
       "\n",
       "                                      UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                          \n",
       "Mesa Community College                  0.0257     0.0682    0.6457         1   \n",
       "Hair Academy Inc-New Carrollton         0.0000     0.0000    0.4683         1   \n",
       "National College of Natural Medicine       NaN        NaN       NaN         1   \n",
       "\n",
       "                                      PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                             \n",
       "Mesa Community College                 0.3423    0.2207   0.4010   \n",
       "Hair Academy Inc-New Carrollton        0.9756    1.0000   0.5882   \n",
       "National College of Natural Medicine      NaN       NaN      NaN   \n",
       "\n",
       "                                      MD_EARN_WNE_P10  GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                     \n",
       "Mesa Community College                          35200                8000  \n",
       "Hair Academy Inc-New Carrollton                 15200                9666  \n",
       "National College of Natural Medicine              NaN   PrivacySuppressed  \n",
       "\n",
       "[3 rows x 26 columns]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start = 'Mesa Community College'\n",
    "stop = 'Spokane Community College'\n",
    "college[start:stop:1500]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'(slice(None, 10, None), ['CITY', 'STABBR'])' is an invalid key",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-53-e9387238cca0>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mcollege\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'CITY'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'STABBR'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;31m# 格式不对，[]内的内容必须是切片。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   2798\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlevels\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2799\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2800\u001b[1;33m             \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2801\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2802\u001b[0m                 \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2644\u001b[0m                 )\n\u001b[0;32m   2645\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2646\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2647\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2648\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: '(slice(None, 10, None), ['CITY', 'STABBR'])' is an invalid key"
     ]
    }
   ],
   "source": [
    "college[:10, ['CITY', 'STABBR']] # 格式不对，[]内的内容必须是切片。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Athens State University</th>\n",
       "      <td>Athens</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Auburn University at Montgomery</th>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Auburn University</th>\n",
       "      <td>Auburn</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           CITY STABBR\n",
       "INSTNM                                                \n",
       "Alabama A & M University                 Normal     AL\n",
       "University of Alabama at Birmingham  Birmingham     AL\n",
       "Amridge University                   Montgomery     AL\n",
       "...                                         ...    ...\n",
       "Athens State University                  Athens     AL\n",
       "Auburn University at Montgomery      Montgomery     AL\n",
       "Auburn University                        Auburn     AL\n",
       "\n",
       "[10 rows x 2 columns]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "first_ten_instnm = college.index[:10]\n",
    "college.loc[first_ten_instnm, ['CITY', 'STABBR']] # 需要同时指定行列的话用loc或iloc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字典序切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'Sp'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_slice_bound\u001b[1;34m(self, label, side, kind)\u001b[0m\n\u001b[0;32m   4843\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4844\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_searchsorted_monotonic\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mside\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4845\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36m_searchsorted_monotonic\u001b[1;34m(self, label, side)\u001b[0m\n\u001b[0;32m   4804\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4805\u001b[1;33m         \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"index must be monotonic increasing or decreasing\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4806\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: index must be monotonic increasing or decreasing",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-55-1a94adfe5f82>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mcollege\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'data/college.csv'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex_col\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'INSTNM'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mcollege\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Sp'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;34m'Su'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;31m# 未排序，无法得到正确形式的切片。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   1766\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1767\u001b[0m             \u001b[0mmaybe_callable\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_if_callable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1768\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmaybe_callable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1769\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1770\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_is_scalar_access\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mTuple\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   1910\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslice\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1911\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_key\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1912\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_slice_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1913\u001b[0m         \u001b[1;32melif\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_bool_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1914\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getbool_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_get_slice_axis\u001b[1;34m(self, slice_obj, axis)\u001b[0m\n\u001b[0;32m   1794\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1795\u001b[0m         \u001b[0mlabels\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1796\u001b[1;33m         indexer = labels.slice_indexer(\n\u001b[0m\u001b[0;32m   1797\u001b[0m             \u001b[0mslice_obj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslice_obj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslice_obj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1798\u001b[0m         )\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mslice_indexer\u001b[1;34m(self, start, end, step, kind)\u001b[0m\n\u001b[0;32m   4710\u001b[0m         \u001b[0mslice\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4711\u001b[0m         \"\"\"\n\u001b[1;32m-> 4712\u001b[1;33m         \u001b[0mstart_slice\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mslice_locs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstart\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstep\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mkind\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4713\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4714\u001b[0m         \u001b[1;31m# return a slice\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mslice_locs\u001b[1;34m(self, start, end, step, kind)\u001b[0m\n\u001b[0;32m   4923\u001b[0m         \u001b[0mstart_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4924\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mstart\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4925\u001b[1;33m             \u001b[0mstart_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_slice_bound\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstart\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"left\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4926\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mstart_slice\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4927\u001b[0m             \u001b[0mstart_slice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_slice_bound\u001b[1;34m(self, label, side, kind)\u001b[0m\n\u001b[0;32m   4845\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4846\u001b[0m                 \u001b[1;31m# raise the original KeyError\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4847\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4848\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4849\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mslc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_slice_bound\u001b[1;34m(self, label, side, kind)\u001b[0m\n\u001b[0;32m   4839\u001b[0m         \u001b[1;31m# we need to look up the label\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4840\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4841\u001b[1;33m             \u001b[0mslc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabel\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4842\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4843\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2646\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2647\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2648\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2649\u001b[0m         \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2650\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msize\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Sp'"
     ]
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college.loc['Sp':'Su'] # 未排序，无法得到正确形式的切片。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A &amp; W Healthcare Educators</th>\n",
       "      <td>New Orleans</td>\n",
       "      <td>LA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.1250</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7018</td>\n",
       "      <td>0.8596</td>\n",
       "      <td>0.6667</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19022.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A T Still University of Health Sciences</th>\n",
       "      <td>Kirksville</td>\n",
       "      <td>MO</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>219800</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ABC Beauty Academy</th>\n",
       "      <td>Garland</td>\n",
       "      <td>TX</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>0.7857</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.8286</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ABC Beauty College Inc</th>\n",
       "      <td>Arkadelphia</td>\n",
       "      <td>AR</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>38.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2105</td>\n",
       "      <td>1</td>\n",
       "      <td>0.9815</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.4688</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>16500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AI Miami International University of Art and Design</th>\n",
       "      <td>Miami</td>\n",
       "      <td>FL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2778.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0018</td>\n",
       "      <td>0.0025</td>\n",
       "      <td>0.4644</td>\n",
       "      <td>0.2185</td>\n",
       "      <td>1</td>\n",
       "      <td>0.5507</td>\n",
       "      <td>0.6966</td>\n",
       "      <td>0.3262</td>\n",
       "      <td>29900</td>\n",
       "      <td>31000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                           CITY STABBR  HBCU  \\\n",
       "INSTNM                                                                         \n",
       "A & W Healthcare Educators                          New Orleans     LA   0.0   \n",
       "A T Still University of Health Sciences              Kirksville     MO   0.0   \n",
       "ABC Beauty Academy                                      Garland     TX   0.0   \n",
       "ABC Beauty College Inc                              Arkadelphia     AR   0.0   \n",
       "AI Miami International University of Art and De...        Miami     FL   0.0   \n",
       "\n",
       "                                                    MENONLY  WOMENONLY  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                              0.0        0.0   \n",
       "A T Still University of Health Sciences                 0.0        0.0   \n",
       "ABC Beauty Academy                                      0.0        0.0   \n",
       "ABC Beauty College Inc                                  0.0        0.0   \n",
       "AI Miami International University of Art and De...      0.0        0.0   \n",
       "\n",
       "                                                    RELAFFIL  SATVRMID  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                                 0       NaN   \n",
       "A T Still University of Health Sciences                    0       NaN   \n",
       "ABC Beauty Academy                                         0       NaN   \n",
       "ABC Beauty College Inc                                     0       NaN   \n",
       "AI Miami International University of Art and De...         0       NaN   \n",
       "\n",
       "                                                    SATMTMID  DISTANCEONLY  \\\n",
       "INSTNM                                                                       \n",
       "A & W Healthcare Educators                               NaN           0.0   \n",
       "A T Still University of Health Sciences                  NaN           0.0   \n",
       "ABC Beauty Academy                                       NaN           0.0   \n",
       "ABC Beauty College Inc                                   NaN           0.0   \n",
       "AI Miami International University of Art and De...       NaN           0.0   \n",
       "\n",
       "                                                      UGDS  ...  UGDS_2MOR  \\\n",
       "INSTNM                                                      ...              \n",
       "A & W Healthcare Educators                            40.0  ...     0.0000   \n",
       "A T Still University of Health Sciences                NaN  ...        NaN   \n",
       "ABC Beauty Academy                                    30.0  ...     0.0000   \n",
       "ABC Beauty College Inc                                38.0  ...     0.0000   \n",
       "AI Miami International University of Art and De...  2778.0  ...     0.0018   \n",
       "\n",
       "                                                    UGDS_NRA  UGDS_UNKN  \\\n",
       "INSTNM                                                                    \n",
       "A & W Healthcare Educators                            0.0000     0.0000   \n",
       "A T Still University of Health Sciences                  NaN        NaN   \n",
       "ABC Beauty Academy                                    0.0000     0.0000   \n",
       "ABC Beauty College Inc                                0.0000     0.0000   \n",
       "AI Miami International University of Art and De...    0.0025     0.4644   \n",
       "\n",
       "                                                    PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                   \n",
       "A & W Healthcare Educators                            0.1250         1   \n",
       "A T Still University of Health Sciences                  NaN         1   \n",
       "ABC Beauty Academy                                    0.0000         0   \n",
       "ABC Beauty College Inc                                0.2105         1   \n",
       "AI Miami International University of Art and De...    0.2185         1   \n",
       "\n",
       "                                                    PCTPELL  PCTFLOAN  \\\n",
       "INSTNM                                                                  \n",
       "A & W Healthcare Educators                           0.7018    0.8596   \n",
       "A T Still University of Health Sciences                 NaN       NaN   \n",
       "ABC Beauty Academy                                   0.7857    0.0000   \n",
       "ABC Beauty College Inc                               0.9815    1.0000   \n",
       "AI Miami International University of Art and De...   0.5507    0.6966   \n",
       "\n",
       "                                                    UG25ABV  \\\n",
       "INSTNM                                                        \n",
       "A & W Healthcare Educators                           0.6667   \n",
       "A T Still University of Health Sciences                 NaN   \n",
       "ABC Beauty Academy                                   0.8286   \n",
       "ABC Beauty College Inc                               0.4688   \n",
       "AI Miami International University of Art and De...   0.3262   \n",
       "\n",
       "                                                      MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                                  \n",
       "A & W Healthcare Educators                                        NaN   \n",
       "A T Still University of Health Sciences                        219800   \n",
       "ABC Beauty Academy                                                NaN   \n",
       "ABC Beauty College Inc                              PrivacySuppressed   \n",
       "AI Miami International University of Art and De...              29900   \n",
       "\n",
       "                                                    GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                  \n",
       "A & W Healthcare Educators                                     19022.5  \n",
       "A T Still University of Health Sciences              PrivacySuppressed  \n",
       "ABC Beauty Academy                                   PrivacySuppressed  \n",
       "ABC Beauty College Inc                                           16500  \n",
       "AI Miami International University of Art and De...               31000  \n",
       "\n",
       "[5 rows x 26 columns]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = college.sort_index() # 根据索引排序，内部核外存储了索引的字典序。\n",
    "college.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Spa Tech Institute-Ipswich</th>\n",
       "      <td>Ipswich</td>\n",
       "      <td>MA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>37.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0541</td>\n",
       "      <td>0.4054</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2656</td>\n",
       "      <td>0.3906</td>\n",
       "      <td>0.7907</td>\n",
       "      <td>21500</td>\n",
       "      <td>6333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spa Tech Institute-Plymouth</th>\n",
       "      <td>Plymouth</td>\n",
       "      <td>MA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>153.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2484</td>\n",
       "      <td>0.3399</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3716</td>\n",
       "      <td>0.4266</td>\n",
       "      <td>0.6250</td>\n",
       "      <td>21500</td>\n",
       "      <td>6333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spa Tech Institute-Westboro</th>\n",
       "      <td>Westboro</td>\n",
       "      <td>MA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0222</td>\n",
       "      <td>0.5778</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3409</td>\n",
       "      <td>0.4545</td>\n",
       "      <td>0.6882</td>\n",
       "      <td>21500</td>\n",
       "      <td>6333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stylemaster College of Hair Design</th>\n",
       "      <td>Longview</td>\n",
       "      <td>WA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.013</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8036</td>\n",
       "      <td>0.7024</td>\n",
       "      <td>0.4510</td>\n",
       "      <td>17000</td>\n",
       "      <td>13320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Styles and Profiles Beauty College</th>\n",
       "      <td>Selmer</td>\n",
       "      <td>TN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>31.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.8182</td>\n",
       "      <td>0.7955</td>\n",
       "      <td>0.2400</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Styletrends Barber and Hairstyling Academy</th>\n",
       "      <td>Rock Hill</td>\n",
       "      <td>SC</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.5556</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>0.3529</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>9495.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>201 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                 CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                        \n",
       "Spa Tech Institute-Ipswich                    Ipswich     MA   0.0      0.0   \n",
       "Spa Tech Institute-Plymouth                  Plymouth     MA   0.0      0.0   \n",
       "Spa Tech Institute-Westboro                  Westboro     MA   0.0      0.0   \n",
       "...                                               ...    ...   ...      ...   \n",
       "Stylemaster College of Hair Design           Longview     WA   0.0      0.0   \n",
       "Styles and Profiles Beauty College             Selmer     TN   0.0      0.0   \n",
       "Styletrends Barber and Hairstyling Academy  Rock Hill     SC   0.0      0.0   \n",
       "\n",
       "                                            WOMENONLY  RELAFFIL  SATVRMID  \\\n",
       "INSTNM                                                                      \n",
       "Spa Tech Institute-Ipswich                        0.0         0       NaN   \n",
       "Spa Tech Institute-Plymouth                       0.0         0       NaN   \n",
       "Spa Tech Institute-Westboro                       0.0         0       NaN   \n",
       "...                                               ...       ...       ...   \n",
       "Stylemaster College of Hair Design                0.0         0       NaN   \n",
       "Styles and Profiles Beauty College                0.0         0       NaN   \n",
       "Styletrends Barber and Hairstyling Academy        0.0         0       NaN   \n",
       "\n",
       "                                            SATMTMID  DISTANCEONLY   UGDS  \\\n",
       "INSTNM                                                                      \n",
       "Spa Tech Institute-Ipswich                       NaN           0.0   37.0   \n",
       "Spa Tech Institute-Plymouth                      NaN           0.0  153.0   \n",
       "Spa Tech Institute-Westboro                      NaN           0.0   90.0   \n",
       "...                                              ...           ...    ...   \n",
       "Stylemaster College of Hair Design               NaN           0.0   77.0   \n",
       "Styles and Profiles Beauty College               NaN           0.0   31.0   \n",
       "Styletrends Barber and Hairstyling Academy       NaN           0.0   45.0   \n",
       "\n",
       "                                            ...  UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                      ...                        \n",
       "Spa Tech Institute-Ipswich                  ...      0.000       0.0   \n",
       "Spa Tech Institute-Plymouth                 ...      0.000       0.0   \n",
       "Spa Tech Institute-Westboro                 ...      0.000       0.0   \n",
       "...                                         ...        ...       ...   \n",
       "Stylemaster College of Hair Design          ...      0.013       0.0   \n",
       "Styles and Profiles Beauty College          ...      0.000       0.0   \n",
       "Styletrends Barber and Hairstyling Academy  ...      0.000       0.0   \n",
       "\n",
       "                                            UGDS_UNKN  PPTUG_EF  CURROPER  \\\n",
       "INSTNM                                                                      \n",
       "Spa Tech Institute-Ipswich                     0.0541    0.4054         1   \n",
       "Spa Tech Institute-Plymouth                    0.2484    0.3399         1   \n",
       "Spa Tech Institute-Westboro                    0.0222    0.5778         1   \n",
       "...                                               ...       ...       ...   \n",
       "Stylemaster College of Hair Design             0.0000    0.0000         1   \n",
       "Styles and Profiles Beauty College             0.0000    0.0000         1   \n",
       "Styletrends Barber and Hairstyling Academy     0.0000    0.5556         0   \n",
       "\n",
       "                                            PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                                   \n",
       "Spa Tech Institute-Ipswich                   0.2656    0.3906   0.7907   \n",
       "Spa Tech Institute-Plymouth                  0.3716    0.4266   0.6250   \n",
       "Spa Tech Institute-Westboro                  0.3409    0.4545   0.6882   \n",
       "...                                             ...       ...      ...   \n",
       "Stylemaster College of Hair Design           0.8036    0.7024   0.4510   \n",
       "Styles and Profiles Beauty College           0.8182    0.7955   0.2400   \n",
       "Styletrends Barber and Hairstyling Academy   1.0000    1.0000   0.3529   \n",
       "\n",
       "                                              MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                          \n",
       "Spa Tech Institute-Ipswich                              21500   \n",
       "Spa Tech Institute-Plymouth                             21500   \n",
       "Spa Tech Institute-Westboro                             21500   \n",
       "...                                                       ...   \n",
       "Stylemaster College of Hair Design                      17000   \n",
       "Styles and Profiles Beauty College          PrivacySuppressed   \n",
       "Styletrends Barber and Hairstyling Academy  PrivacySuppressed   \n",
       "\n",
       "                                            GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                          \n",
       "Spa Tech Institute-Ipswich                                6333  \n",
       "Spa Tech Institute-Plymouth                               6333  \n",
       "Spa Tech Institute-Westboro                               6333  \n",
       "...                                                        ...  \n",
       "Stylemaster College of Hair Design                       13320  \n",
       "Styles and Profiles Beauty College           PrivacySuppressed  \n",
       "Styletrends Barber and Hairstyling Academy              9495.5  \n",
       "\n",
       "[201 rows x 26 columns]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc['Sp':'Su'] # 根据索引的字典序自动匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = college.sort_index(ascending=False) # 降序排序\n",
    "college.index.is_monotonic_decreasing # 检查索引是否递减"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>...</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Dyersburg State Community College</th>\n",
       "      <td>Dyersburg</td>\n",
       "      <td>TN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2001.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0185</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0085</td>\n",
       "      <td>0.4423</td>\n",
       "      <td>1</td>\n",
       "      <td>0.4921</td>\n",
       "      <td>0.2493</td>\n",
       "      <td>0.3097</td>\n",
       "      <td>26800</td>\n",
       "      <td>7475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dutchess Community College</th>\n",
       "      <td>Poughkeepsie</td>\n",
       "      <td>NY</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6885.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0446</td>\n",
       "      <td>0.0129</td>\n",
       "      <td>0.0049</td>\n",
       "      <td>0.3312</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2464</td>\n",
       "      <td>0.1936</td>\n",
       "      <td>0.1806</td>\n",
       "      <td>32500</td>\n",
       "      <td>10250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dutchess BOCES-Practical Nursing Program</th>\n",
       "      <td>Poughkeepsie</td>\n",
       "      <td>NY</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>155.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0581</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.7548</td>\n",
       "      <td>1</td>\n",
       "      <td>0.5294</td>\n",
       "      <td>0.6275</td>\n",
       "      <td>0.5430</td>\n",
       "      <td>36500</td>\n",
       "      <td>9500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BJ's Beauty &amp; Barber College</th>\n",
       "      <td>Auburn</td>\n",
       "      <td>WA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0714</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0714</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.5192</td>\n",
       "      <td>0.6154</td>\n",
       "      <td>0.2917</td>\n",
       "      <td>NaN</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BIR Training Center</th>\n",
       "      <td>Chicago</td>\n",
       "      <td>IL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2132.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.1806</td>\n",
       "      <td>0</td>\n",
       "      <td>0.6700</td>\n",
       "      <td>0.6998</td>\n",
       "      <td>0.6741</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>15394</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B M Spurr School of Practical Nursing</th>\n",
       "      <td>Glen Dale</td>\n",
       "      <td>WV</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>31.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>1</td>\n",
       "      <td>0.4722</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.4444</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1411 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  CITY STABBR  HBCU  MENONLY  \\\n",
       "INSTNM                                                                         \n",
       "Dyersburg State Community College            Dyersburg     TN   0.0      0.0   \n",
       "Dutchess Community College                Poughkeepsie     NY   0.0      0.0   \n",
       "Dutchess BOCES-Practical Nursing Program  Poughkeepsie     NY   0.0      0.0   \n",
       "...                                                ...    ...   ...      ...   \n",
       "BJ's Beauty & Barber College                    Auburn     WA   0.0      0.0   \n",
       "BIR Training Center                            Chicago     IL   0.0      0.0   \n",
       "B M Spurr School of Practical Nursing        Glen Dale     WV   0.0      0.0   \n",
       "\n",
       "                                          WOMENONLY  RELAFFIL  SATVRMID  \\\n",
       "INSTNM                                                                    \n",
       "Dyersburg State Community College               0.0         0       NaN   \n",
       "Dutchess Community College                      0.0         0       NaN   \n",
       "Dutchess BOCES-Practical Nursing Program        0.0         0       NaN   \n",
       "...                                             ...       ...       ...   \n",
       "BJ's Beauty & Barber College                    0.0         0       NaN   \n",
       "BIR Training Center                             0.0         0       NaN   \n",
       "B M Spurr School of Practical Nursing           0.0         0       NaN   \n",
       "\n",
       "                                          SATMTMID  DISTANCEONLY    UGDS  ...  \\\n",
       "INSTNM                                                                    ...   \n",
       "Dyersburg State Community College              NaN           0.0  2001.0  ...   \n",
       "Dutchess Community College                     NaN           0.0  6885.0  ...   \n",
       "Dutchess BOCES-Practical Nursing Program       NaN           0.0   155.0  ...   \n",
       "...                                            ...           ...     ...  ...   \n",
       "BJ's Beauty & Barber College                   NaN           0.0    28.0  ...   \n",
       "BIR Training Center                            NaN           0.0  2132.0  ...   \n",
       "B M Spurr School of Practical Nursing          NaN           0.0    31.0  ...   \n",
       "\n",
       "                                          UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \\\n",
       "INSTNM                                                                     \n",
       "Dyersburg State Community College            0.0185    0.0010     0.0085   \n",
       "Dutchess Community College                   0.0446    0.0129     0.0049   \n",
       "Dutchess BOCES-Practical Nursing Program     0.0581    0.0000     0.0000   \n",
       "...                                             ...       ...        ...   \n",
       "BJ's Beauty & Barber College                 0.0714    0.0000     0.0714   \n",
       "BIR Training Center                          0.0000    0.0000     0.0000   \n",
       "B M Spurr School of Practical Nursing        0.0000    0.0000     0.0000   \n",
       "\n",
       "                                          PPTUG_EF  CURROPER  PCTPELL  \\\n",
       "INSTNM                                                                  \n",
       "Dyersburg State Community College           0.4423         1   0.4921   \n",
       "Dutchess Community College                  0.3312         1   0.2464   \n",
       "Dutchess BOCES-Practical Nursing Program    0.7548         1   0.5294   \n",
       "...                                            ...       ...      ...   \n",
       "BJ's Beauty & Barber College                0.0000         1   0.5192   \n",
       "BIR Training Center                         0.1806         0   0.6700   \n",
       "B M Spurr School of Practical Nursing       0.0000         1   0.4722   \n",
       "\n",
       "                                          PCTFLOAN  UG25ABV  \\\n",
       "INSTNM                                                        \n",
       "Dyersburg State Community College           0.2493   0.3097   \n",
       "Dutchess Community College                  0.1936   0.1806   \n",
       "Dutchess BOCES-Practical Nursing Program    0.6275   0.5430   \n",
       "...                                            ...      ...   \n",
       "BJ's Beauty & Barber College                0.6154   0.2917   \n",
       "BIR Training Center                         0.6998   0.6741   \n",
       "B M Spurr School of Practical Nursing       0.0000   0.4444   \n",
       "\n",
       "                                            MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                        \n",
       "Dyersburg State Community College                     26800   \n",
       "Dutchess Community College                            32500   \n",
       "Dutchess BOCES-Practical Nursing Program              36500   \n",
       "...                                                     ...   \n",
       "BJ's Beauty & Barber College                            NaN   \n",
       "BIR Training Center                       PrivacySuppressed   \n",
       "B M Spurr School of Practical Nursing     PrivacySuppressed   \n",
       "\n",
       "                                          GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                        \n",
       "Dyersburg State Community College                       7475  \n",
       "Dutchess Community College                             10250  \n",
       "Dutchess BOCES-Practical Nursing Program                9500  \n",
       "...                                                      ...  \n",
       "BJ's Beauty & Barber College               PrivacySuppressed  \n",
       "BIR Training Center                                    15394  \n",
       "B M Spurr School of Practical Nursing      PrivacySuppressed  \n",
       "\n",
       "[1411 rows x 26 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc['E':'B'] # 递减索引可以这么写"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
